﻿#region zh-CHS 2006 - 2010 DemoSoft 团队 | en 2006-2010 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2010 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Mmose.Core.Common;
using Demo.Mmose.Core.Common.SafeCollections;
using System.Collections;
#endregion

namespace Demo.Mmose.Core.Entity.Suit.Quest
{
    /// <summary>
    /// 
    /// </summary>
    public class QuestObjectiveLine : IEnumerable<QuestObjective>
    {

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="spells"></param>
        public QuestObjectiveLine()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="spells"></param>
        public QuestObjectiveLine( long objectiveId )
        {
            m_Serial = objectiveId;
        }

        #endregion

        #region zh-CHS 共有属性 | en Public Properties

        #region zh-CHS Serial属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Serial m_Serial = Serial.Zero;
        #endregion
        /// <summary>
        /// 唯一序列号GUID
        /// </summary>
        public Serial Serial
        {
            get { return m_Serial; }
            set { m_Serial = value; }
        }

        #endregion

        #region zh-CHS Name属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private string m_Name = string.Empty;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        #endregion

        #region zh-CHS First属性 | en Public Properties

        /// <summary>
        /// 
        /// </summary>
        public QuestObjective First
        {
            get 
            {
                LinkedListNode<QuestObjective> firstQuestObjective = m_QuestObjectiveLine.First;

                if ( firstQuestObjective == null )
                    return null;
                else
                    return firstQuestObjective.Value;
            }
        }

        #endregion

        #region zh-CHS Current属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private LinkedListNode<QuestObjective> m_Current = null;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public QuestObjective Current
        {
            get
            {
                LinkedListNode<QuestObjective> currentQuestObjective = m_Current;
                if ( currentQuestObjective != null )
                    return currentQuestObjective.Value;
                else
                    return null;
            }
        }

        #endregion

        #region zh-CHS Last属性 | en Public Properties

        /// <summary>
        /// 
        /// </summary>
        public QuestObjective Last
        {
            get
            {
                LinkedListNode<QuestObjective> lastQuestObjective = m_QuestObjectiveLine.Last;

                if ( lastQuestObjective == null )
                    return null;
                else
                    return lastQuestObjective.Value;
            }
        }

        #endregion

        #endregion

        #region zh-CHS 共有方法 | en Public Methods

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private SafeLinkedList<QuestObjective> m_QuestObjectiveLine = new SafeLinkedList<QuestObjective>();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="questObjective"></param>
        public void AddQuestObjective( QuestObjective questObjective )
        {
            LinkedListNode<QuestObjective> thisLinkedListNode = m_QuestObjectiveLine.AddLast( questObjective );

            if ( m_Current == null )
                m_Current = thisLinkedListNode;
        }

        /// <summary>
        /// 
        /// </summary>
        public bool ToPreQuestObjective()
        {
            LinkedListNode<QuestObjective> current = m_Current;
            if ( current == null )
                return false;

            LinkedListNode<QuestObjective> previous = current.Previous;
            if ( previous == null )
                return false;

            m_Current = previous;
            
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        public bool ToNextQuestObjective()
        {
            LinkedListNode<QuestObjective> current = m_Current;
            if ( current == null )
                return false;

            LinkedListNode<QuestObjective> next = current.Next;
            if ( next == null )
                return false;

            m_Current = next;

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        public bool ToThisQuestObjective( QuestObjective questObjective )
        {
            //LinkedListNode<QuestObjective> current = m_Current;
            //if ( current == null )
            //    return false;

            //LinkedListNode<QuestObjective> previous = current.Previous;
            //if ( previous == null )
            //    return false;

            //m_Current = previous;

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public QuestObjective[] ToArray()
        {
            return m_QuestObjectiveLine.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator<QuestObjectiveT> ToArray<QuestObjectiveT>() where QuestObjectiveT : QuestObjective
        {
            QuestObjective[] tempArray = this.ToArray();
            if ( tempArray == null )
                yield break;

            for ( int iIndex = 0; iIndex < tempArray.Length; iIndex++ )
            {
                QuestObjectiveT questObjective = tempArray[iIndex] as QuestObjectiveT;
                if ( questObjective == null )
                    continue;
                else
                    yield return questObjective;
            }
        }

        #endregion

        #region zh-CHS 方法覆盖 | en Override Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_Name;
        }
        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator<QuestObjective> GetEnumerator()
        {
            return m_QuestObjectiveLine.GetEnumerator();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
        #endregion

    }

}
#endregion